<html>
<head><meta charset="utf-8"><title>Virtual Terminal Sequence support on Windows · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html">Virtual Terminal Sequence support on Windows</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="243982853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243982853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243982853">(Jun 25 2021 at 23:53)</a>:</h4>
<p>On Windows, starting in Windows 10 as of like 2016 or so, the console <em>can</em> support virtual terminal sequences. However, for backwards compatibility this is off by default, and virtual terminal sequences are not processed by the console. This can be enabled using SetConsoleMode, but the programmer has to have the windows specific knowledge of how to do this.</p>
<p>It would be extremely nice if such a simple thing were available within <code>std::os::windows::io</code> rather than needing to pull in a crate of any kind.</p>



<a name="243984319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243984319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243984319">(Jun 26 2021 at 00:27)</a>:</h4>
<p>Other than the overhead of one system call, what's the <em>downside</em> to enabling this? Is it just that terminal sequences are interpreted rather than spewed to the console verbatim as control characters? Or is there something more?</p>



<a name="243984510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243984510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243984510">(Jun 26 2021 at 00:31)</a>:</h4>
<p>No downside other than potential backward compatibility concern (if the program expected to be able to spit out escape sequences and have them displayed raw).</p>



<a name="243985969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243985969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243985969">(Jun 26 2021 at 00:55)</a>:</h4>
<p>Hard to imagine a case where you'd expect to show a raw ESC and you'd break something if you didn't.</p>



<a name="243986031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243986031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243986031">(Jun 26 2021 at 00:56)</a>:</h4>
<p>I don't think the standard library could call it automatically, but I think it makes sense for any terminal library to do so.</p>



<a name="243986041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243986041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243986041">(Jun 26 2021 at 00:56)</a>:</h4>
<p>Meanwhile, yeah, we ought to provide the function. Want to submit a PR?</p>



<a name="243986078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243986078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243986078">(Jun 26 2021 at 00:57)</a>:</h4>
<p><code>std::os::windows::io::enable_terminal_escapes()</code>, or something roughly along those lines?</p>



<a name="243986087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243986087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243986087">(Jun 26 2021 at 00:57)</a>:</h4>
<p><code>fn enable_terminal_escapes() -&gt; std::io::Result&lt;()&gt;</code></p>



<a name="243986949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243986949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243986949">(Jun 26 2021 at 01:15)</a>:</h4>
<p>oof, well i did ask for it so i guess it is on me to do the PR</p>



<a name="243993563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243993563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243993563">(Jun 26 2021 at 04:11)</a>:</h4>
<p>it's probably worth noting in the docs that the error should be ignored — it would be expected to fail on stuff like mintty (and probably old versions of windows too)</p>



<a name="243993690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243993690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243993690">(Jun 26 2021 at 04:15)</a>:</h4>
<p>Well, if you get an error that means you (probably) can't emit virtual terminal sequences that will be picked up properly. If you were to emit virtual terminal sequences without the terminal interpreting them then it would look like garbled nonsense.</p>



<a name="243993735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243993735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243993735">(Jun 26 2021 at 04:16)</a>:</h4>
<p>actually, that's not true</p>



<a name="243993744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243993744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243993744">(Jun 26 2021 at 04:16)</a>:</h4>
<p>on mintty, vscode, etc. that operation will error, but terminal sequences will still work (since they would work without you doing that)</p>



<a name="243993755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243993755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243993755">(Jun 26 2021 at 04:17)</a>:</h4>
<p>Well in the case of vscode, it depends on what shell vscode is running I suppose.</p>



<a name="243993758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243993758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243993758">(Jun 26 2021 at 04:17)</a>:</h4>
<p>no, it uses xterm.js regardless</p>



<a name="243993763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243993763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243993763">(Jun 26 2021 at 04:18)</a>:</h4>
<p>which interprets the sequence</p>



<a name="243993795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243993795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243993795">(Jun 26 2021 at 04:18)</a>:</h4>
<p>the shell is unrelated</p>



<a name="243993940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243993940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243993940">(Jun 26 2021 at 04:23)</a>:</h4>
<p>oh wild</p>



<a name="243996742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243996742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243996742">(Jun 26 2021 at 05:48)</a>:</h4>
<p>Can mintty be detected and a success be reported?</p>



<a name="243996745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243996745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243996745">(Jun 26 2021 at 05:48)</a>:</h4>
<p>I believe is_atty already checks for a cygwin/mingw terminal.</p>



<a name="243996936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243996936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243996936">(Jun 26 2021 at 05:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows/near/243996742">said</a>:</p>
<blockquote>
<p>Can mintty be detected and a success be reported?</p>
</blockquote>
<p>not 100% reliably, but you can heuristically detect those two. that said, there could be other terminals using the new win10 pty mechanism</p>



<a name="243996937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243996937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243996937">(Jun 26 2021 at 05:54)</a>:</h4>
<p>there's no way to detect them really</p>



<a name="243997345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997345">(Jun 26 2021 at 06:07)</a>:</h4>
<p><span class="user-mention" data-user-id="209168">@Thom Chiovoloni</span> There's no way to detect that your output is a pty?</p>



<a name="243997351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997351">(Jun 26 2021 at 06:07)</a>:</h4>
<p>not reliably</p>



<a name="243997356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997356">(Jun 26 2021 at 06:07)</a>:</h4>
<p>How about unreliably?</p>



<a name="243997358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997358">(Jun 26 2021 at 06:07)</a>:</h4>
<p>you check the file associated with the handle, and make a guess if it refers to a PTY</p>



<a name="243997360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997360">(Jun 26 2021 at 06:07)</a>:</h4>
<p>Ah. :(</p>



<a name="243997401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997401">(Jun 26 2021 at 06:08)</a>:</h4>
<p>So it's not a unique type of handle that you can identify? Is it just a named pipe or similar?</p>



<a name="243997407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997407">(Jun 26 2021 at 06:08)</a>:</h4>
<p>yes, more or less</p>



<a name="243997409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997409">(Jun 26 2021 at 06:08)</a>:</h4>
<p>Sigh.</p>



<a name="243997415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997415">(Jun 26 2021 at 06:08)</a>:</h4>
<p>How about this: is there a way to detect that your output almost certainly <em>isn't</em> a pty?</p>



<a name="243997430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997430">(Jun 26 2021 at 06:09)</a>:</h4>
<p><a href="https://github.com/softprops/atty/blob/master/src/lib.rs#L147-L152">https://github.com/softprops/atty/blob/master/src/lib.rs#L147-L152</a> is the logic, which  is pretty reliable in practice... as long as you're looking for mintty and cytwin</p>



<a name="243997438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997438">(Jun 26 2021 at 06:09)</a>:</h4>
<p>That's really unfortunate. :(</p>



<a name="243997443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997443">(Jun 26 2021 at 06:09)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows/near/243997415">said</a>:</p>
<blockquote>
<p>How about this: is there a way to detect that your output almost certainly <em>isn't</em> a pty?</p>
</blockquote>
<p>hm, i dont know off the top, and am not in a position to do experimenting at the moment.</p>



<a name="243997484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997484">(Jun 26 2021 at 06:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows/near/243997438">said</a>:</p>
<blockquote>
<p>That's really unfortunate. :(</p>
</blockquote>
<p>yes, i 100% agree</p>



<a name="243997495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997495">(Jun 26 2021 at 06:10)</a>:</h4>
<p>I'm not really bothered by the idea of emitting terminal escapes to a terminal that doesn't support them, but I <em>am</em> bothered by the idea of emitting terminal escapes to what turns out to be a redirect to a file, or a simple <code>| less</code> or <code>| more</code> or <code>| grep</code>.</p>



<a name="243997504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997504">(Jun 26 2021 at 06:11)</a>:</h4>
<p>It'd be nice to be able to detect, at a minimum, "is this a regular file" or "is this a regular non-named pipe", and know that that at least is <em>not</em> likely to be a terminal.</p>



<a name="243997587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997587">(Jun 26 2021 at 06:13)</a>:</h4>
<p>in some cases the right call then is to separately open "CONOUT$", and write to it. you also could check if the file exists, which i <em>think</em> it won't for a pty? but I'd have to try. Or at least, I suspect theres some way to get the file name, and then use some windows api to determine that it's at least not a normal file...</p>



<a name="243997625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243997625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243997625">(Jun 26 2021 at 06:14)</a>:</h4>
<p>but yeah, in general it's pretty tricky, and annoying that behaving well and avoiding worst-case bad behavior are often contradictory on terminal apis on all platforms :(</p>



<a name="243998322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243998322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243998322">(Jun 26 2021 at 06:33)</a>:</h4>
<p>Is it reasonable to assume that a pty is always a certain <em>type</em> of handle, like a named pipe?</p>



<a name="243998449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/243998449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#243998449">(Jun 26 2021 at 06:36)</a>:</h4>
<p>For instance, would it help to call <a href="https://docs.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-getnamedpipeinfo">https://docs.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-getnamedpipeinfo</a> and see if it returns useful data?</p>



<a name="244004614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/244004614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#244004614">(Jun 26 2021 at 09:13)</a>:</h4>
<p>so, i dont know if it's a certain type of handle, but i believe it's not a named pipe, since you're supposed to use <code>GetFileInformationByHandleEx</code> to find the "name" of the pty, and that function is supposed to error on any named pipe (according to <a href="https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex">https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex</a> )</p>



<a name="244004857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/244004857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#244004857">(Jun 26 2021 at 09:19)</a>:</h4>
<p>that said, i'd assume that if you look thoroughly there's <em>some</em> distinguishing feature of a pty — i don't <em>think</em> there's a documented one, but it's hard to say, and certainly i never considered looking for cases where that information is more-or-less "leaked".</p>



<a name="244005375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/244005375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#244005375">(Jun 26 2021 at 09:32)</a>:</h4>
<p>Windows has no equivalent for <code>statx(..., STATX_TYPE)</code> for its handles?</p>



<a name="244008052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/244008052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#244008052">(Jun 26 2021 at 10:34)</a>:</h4>
<p>Regardless of what the docs say, you can use <code>GetFileInformationByHandleEx</code> to get the <code>FileNameInfo</code> of a named pipe (though admittedly I don't know how stable this is). Btw, if you just want to check if it's a pipe or not then <code>GetFileType</code>should return <code>FILE_TYPE_PIPE</code>.</p>



<a name="244008574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/244008574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#244008574">(Jun 26 2021 at 10:42)</a>:</h4>
<blockquote>
<p>I don't know how stable this is</p>
</blockquote>
<p>Seems like it's been known to work since at least 2014 which means it's almost certainly de facto stable given Windows stability guarantees.  <a href="https://stackoverflow.com/a/27386874">https://stackoverflow.com/a/27386874</a></p>



<a name="244106341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Virtual%20Terminal%20Sequence%20support%20on%20Windows/near/244106341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Virtual.20Terminal.20Sequence.20support.20on.20Windows.html#244106341">(Jun 28 2021 at 06:35)</a>:</h4>
<p>Upon further investigation, it seems that MSDN is wrong and the most up to date windows terminal will interpret virtual terminal sequences <em>no matter what</em>. It's not just an "the initial stat is unknown at startup" thing. Even if you directly <em>turn off</em> the bit for virtual terminal sequences they will still be processed in the output sequence.</p>
<p>Because it's not documented as working this way it may change in the future, but at least for now we don't need to actually add anything to the standard library.</p>
<p>Test program for reference: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=156e622eabcd7dfe379cccff1e4cb20e">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=156e622eabcd7dfe379cccff1e4cb20e</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>